package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.OrganizationMapper;
import com.example.servicea.entity.OrganizationEntity;
import com.example.servicea.service.OrganizationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @author generator
 * @Date: 2017/10/26 10:58
 */
@Service("organizationServiceImpl")
public class OrganizationServiceImpl implements OrganizationService {
	@Autowired
	private OrganizationMapper organizationMapper;

    @Override
    public boolean insert(OrganizationEntity obj){
        return SqlHelper.retBool(organizationMapper.insert(obj));
    }
    @Override
    public List<OrganizationEntity> selectList(OrganizationEntity organization){
        EntityWrapper<OrganizationEntity> query = new EntityWrapper<OrganizationEntity>();
		return organizationMapper.selectList(query);
	}

    @Override
    public Page selectPage(OrganizationEntity organization, String page, String limit){
        EntityWrapper<OrganizationEntity> query = new EntityWrapper<OrganizationEntity>();
        if(StringUtils.isNotBlank(organization.name)){
            query.like("name",organization.name);
        }
        List<OrganizationEntity> list = organizationMapper.selectPage(
                new Page<OrganizationEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = organizationMapper.selectCount(query);
        Page organizationEntityPage = new Page();
        return organizationEntityPage;
	}
    @Override
    public int selectCount(OrganizationEntity organization){
        EntityWrapper<OrganizationEntity> query = new EntityWrapper<OrganizationEntity>();
        return organizationMapper.selectCount(query);
	}

    @Override
    public OrganizationEntity selectOne(OrganizationEntity organization){
        return organizationMapper.selectOne(new OrganizationEntity());
	}

    @Override
    public OrganizationEntity selectById(String id){
        return organizationMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(OrganizationEntity organization){
        return SqlHelper.retBool(organizationMapper.updateById(organization));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(organizationMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(organizationMapper.deleteBatchIds(list));
	}
	
}
